export default {
    init: function (callback){
        const AK = '2hdKtGq5POwaclkAd1ADMnVNDmMuQDoF'
        const BMap_URL = `https://api.map.baidu.com/api?v=1.0&type=webgl&ak=${AK}&s=1&callback=onBMapCallback`
        return new Promise((resolve, reject) => {
            // 如果已加载直接返回
            if(typeof BMapGL !== 'undefined') {
                resolve(BMapGL);
                return true;
            }
            // 百度地图异步加载回调处理
            window.onBMapCallback = function () {
                resolve(BMapGL);
            };
            // 插入script脚本
            let scriptNode = document.createElement('script');
            scriptNode.setAttribute('type', 'text/javascript');
            scriptNode.setAttribute('src', BMap_URL);
            document.body.appendChild(scriptNode);
        });
    }
}